#include<iostream>
#include<memory>
#include<string>

class Meal
{
public:
    Meal():food_(""),drink_(""){};
    std::string getFood(void) const{return food_;};
    std::string getDrink(void) const{return drink_;};

    void setFood(std::string food){food_ = food;};
    void setDrink(std::string drink){drink_ = drink;};

    friend std::ostream& operator<<(std::ostream& os,Meal &meal)
    {
        os << "主食:" << meal.food_ << "\t" << "饮料:" << meal.drink_ << "\n";
        return os;
    }
private:
    std::string food_;
    std::string drink_;
};

class MealBuilder
{
    protected:
        Meal *meal_;
    public:
        MealBuilder():meal_(new Meal){};
        virtual ~MealBuilder(){if(meal_)delete meal_;};
        virtual void buildFood() = 0;
        virtual void buildDrink() = 0;
        Meal* getResult(){return meal_;};
};

class MealA:public MealBuilder
{
    public:
        void buildFood()override{meal_ ->setFood("汉堡包");};
        void buildDrink()override{meal_ ->setDrink("可口可乐");};
};

class MealB:public MealBuilder
{
    public:
        void buildFood()override{meal_ ->setFood("披萨");};
        void buildDrink()override{meal_ ->setDrink("橙汁");};
};

class KFCWaiter
{
    private:
        MealBuilder *builder_;
    public:
       KFCWaiter():builder_(nullptr){};
       void setBuilder(MealBuilder *builder){builder_ = builder;};
       Meal* constructor(){builder_->buildFood();builder_->buildDrink();return builder_->getResult();};
};

int main(int argc, char const *argv[])
{
     
    std::shared_ptr<MealBuilder> build = std::make_shared<MealB>();
    KFCWaiter waiter;
    waiter.setBuilder(build.get());
    
    std::shared_ptr<Meal> meal (waiter.constructor());

    std::cout << *meal;
    return 0;
}
